<template>
  <el-form style="width: 250px" :rules="rules" :model="temp" label-width="80px" size="mini">
    <el-form-item label="原始密码" prop="old_password">
      <el-input v-model="temp.old_password" maxlength="20" minlength="6"  type="password" show-password/>
    </el-form-item>
    <el-form-item label="新密码" prop="new_password">
      <el-input v-model="temp.new_password" maxlength="20" minlength="6"  type="password" show-password/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">重置密码</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {resetPwd} from "@/api/user";
export default {
  data(){
    return {
      temp:{
        new_password:'',
        old_password:''
      },
      rules: {
        new_password: [{ required: true, pattern:/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,message: '密码至少包含 数字和英文，长度6-20', trigger: 'blur' }],
      },
    }
  },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: ''
        }
      }
    }
  },
  methods: {
    submit() {
      resetPwd(this.temp).then(res => {
        if(res.code == 20000){
          this.$message.success('密码已重置，请重新登录')
        }else{
          this.$message.error(res.message)
        }
      })
    }
  }
}
</script>
